<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta name="generator" content="VuePress 2.0.0-beta.27">
    <link rel="icon" href="favicon.ico"><meta name="keywords" content="Cosla前端,Cosla开发,Cosla文档,酷斯啦前端,酷斯啦开发,酷斯啦文档"><title>小程序端开发事项 | 前端团队开发文档</title><meta name="description" content="Cosla开发，Cosla前端团队开发文档">
    <link rel="preload" href="/assets/js/runtime~app.7eeb5ba6.js" as="script"><link rel="preload" href="/assets/css/styles.a0dfb1ca.css" as="style"><link rel="preload" href="/assets/js/6135.d16fec79.js" as="script"><link rel="preload" href="/assets/js/app.4602c005.js" as="script">
    <link rel="stylesheet" href="/assets/css/styles.a0dfb1ca.css">
  </head>
  <body>
    <div id="app"><!--[--><div class="theme-container"><!--[--><header class="navbar"><div class="toggle-sidebar-button" title="toggle sidebar" aria-expanded="false" role="button" tabindex="0"><div class="icon" aria-hidden="true"><span></span><span></span><span></span></div></div><span><a href="/" class=""><!----><span class="site-name can-hide">前端团队开发文档</span></a></span><div class="navbar-links-wrapper" style=""><!--[--><!--]--><nav class="navbar-links can-hide"><!--[--><div class="navbar-links-item"><a href="/pages/resourcePack/" class="nav-link" aria-label="资源包"><!--[--><!--]--> 资源包 <!--[--><!--]--></a></div><div class="navbar-links-item"><a href="/pages/knowledge/developmentNorm/" class="nav-link" aria-label="知识库"><!--[--><!--]--> 知识库 <!--[--><!--]--></a></div><div class="navbar-links-item"><div class="dropdown-wrapper"><button class="dropdown-title" type="button" aria-label="开发事项"><span class="title">开发事项</span><span class="arrow down"></span></button><button class="mobile-dropdown-title" type="button" aria-label="开发事项"><span class="title">开发事项</span><span class="right arrow"></span></button><!--[--><ul style="display:none;" class="nav-dropdown"><!--[--><li class="dropdown-item"><a href="/pages/developAttention/vehicleWebClient/" class="nav-link" aria-label="网页端"><!--[--><!--]--> 网页端 <!--[--><!--]--></a></li><li class="dropdown-item"><a aria-current="page" href="/pages/developAttention/vehicleMiniprogram/" class="router-link-active router-link-exact-active nav-link router-link-active" aria-label="小程序端"><!--[--><!--]--> 小程序端 <!--[--><!--]--></a></li><!--]--></ul><!--]--></div></div><div class="navbar-links-item"><div class="dropdown-wrapper"><button class="dropdown-title" type="button" aria-label="自定义组件"><span class="title">自定义组件</span><span class="arrow down"></span></button><button class="mobile-dropdown-title" type="button" aria-label="自定义组件"><span class="title">自定义组件</span><span class="right arrow"></span></button><!--[--><ul style="display:none;" class="nav-dropdown"><!--[--><li class="dropdown-item"><a href="/pages/customComponents/vehicleWebClient/detailsLayout/" class="nav-link" aria-label="网页端"><!--[--><!--]--> 网页端 <!--[--><!--]--></a></li><li class="dropdown-item"><a href="/pages/customComponents/vehicleMiniprogram/plate/" class="nav-link" aria-label="小程序端"><!--[--><!--]--> 小程序端 <!--[--><!--]--></a></li><!--]--></ul><!--]--></div></div><!--]--></nav><!--[--><!--]--><button class="toggle-dark-button" title="toggle dark mode"><svg style="" class="icon" focusable="false" viewBox="0 0 32 32"><path d="M16 12.005a4 4 0 1 1-4 4a4.005 4.005 0 0 1 4-4m0-2a6 6 0 1 0 6 6a6 6 0 0 0-6-6z" fill="currentColor"></path><path d="M5.394 6.813l1.414-1.415l3.506 3.506L8.9 10.318z" fill="currentColor"></path><path d="M2 15.005h5v2H2z" fill="currentColor"></path><path d="M5.394 25.197L8.9 21.691l1.414 1.415l-3.506 3.505z" fill="currentColor"></path><path d="M15 25.005h2v5h-2z" fill="currentColor"></path><path d="M21.687 23.106l1.414-1.415l3.506 3.506l-1.414 1.414z" fill="currentColor"></path><path d="M25 15.005h5v2h-5z" fill="currentColor"></path><path d="M21.687 8.904l3.506-3.506l1.414 1.415l-3.506 3.505z" fill="currentColor"></path><path d="M15 2.005h2v5h-2z" fill="currentColor"></path></svg><svg style="display:none;" class="icon" focusable="false" viewBox="0 0 32 32"><path d="M13.502 5.414a15.075 15.075 0 0 0 11.594 18.194a11.113 11.113 0 0 1-7.975 3.39c-.138 0-.278.005-.418 0a11.094 11.094 0 0 1-3.2-21.584M14.98 3a1.002 1.002 0 0 0-.175.016a13.096 13.096 0 0 0 1.825 25.981c.164.006.328 0 .49 0a13.072 13.072 0 0 0 10.703-5.555a1.01 1.01 0 0 0-.783-1.565A13.08 13.08 0 0 1 15.89 4.38A1.015 1.015 0 0 0 14.98 3z" fill="currentColor"></path></svg></button><!----></div></header><!--]--><div class="sidebar-mask"></div><!--[--><aside class="sidebar"><nav class="navbar-links"><!--[--><div class="navbar-links-item"><a href="/pages/resourcePack/" class="nav-link" aria-label="资源包"><!--[--><!--]--> 资源包 <!--[--><!--]--></a></div><div class="navbar-links-item"><a href="/pages/knowledge/developmentNorm/" class="nav-link" aria-label="知识库"><!--[--><!--]--> 知识库 <!--[--><!--]--></a></div><div class="navbar-links-item"><div class="dropdown-wrapper"><button class="dropdown-title" type="button" aria-label="开发事项"><span class="title">开发事项</span><span class="arrow down"></span></button><button class="mobile-dropdown-title" type="button" aria-label="开发事项"><span class="title">开发事项</span><span class="right arrow"></span></button><!--[--><ul style="display:none;" class="nav-dropdown"><!--[--><li class="dropdown-item"><a href="/pages/developAttention/vehicleWebClient/" class="nav-link" aria-label="网页端"><!--[--><!--]--> 网页端 <!--[--><!--]--></a></li><li class="dropdown-item"><a aria-current="page" href="/pages/developAttention/vehicleMiniprogram/" class="router-link-active router-link-exact-active nav-link router-link-active" aria-label="小程序端"><!--[--><!--]--> 小程序端 <!--[--><!--]--></a></li><!--]--></ul><!--]--></div></div><div class="navbar-links-item"><div class="dropdown-wrapper"><button class="dropdown-title" type="button" aria-label="自定义组件"><span class="title">自定义组件</span><span class="arrow down"></span></button><button class="mobile-dropdown-title" type="button" aria-label="自定义组件"><span class="title">自定义组件</span><span class="right arrow"></span></button><!--[--><ul style="display:none;" class="nav-dropdown"><!--[--><li class="dropdown-item"><a href="/pages/customComponents/vehicleWebClient/detailsLayout/" class="nav-link" aria-label="网页端"><!--[--><!--]--> 网页端 <!--[--><!--]--></a></li><li class="dropdown-item"><a href="/pages/customComponents/vehicleMiniprogram/plate/" class="nav-link" aria-label="小程序端"><!--[--><!--]--> 小程序端 <!--[--><!--]--></a></li><!--]--></ul><!--]--></div></div><!--]--></nav><!--[--><!--]--><ul class="sidebar-links"><!--[--><!--[--><a aria-current="page" href="/pages/developAttention/vehicleMiniprogram/" class="router-link-active router-link-exact-active nav-link router-link-active sidebar-heading sidebar-item active" aria-label="小程序端开发事项"><!--[--><!--]--> 小程序端开发事项 <!--[--><!--]--></a><ul class=""><li><!--[--><a aria-current="page" href="/pages/developAttention/vehicleMiniprogram/#技术栈" class="router-link-active router-link-exact-active nav-link sidebar-item" aria-label="技术栈"><!--[--><!--]--> 技术栈 <!--[--><!--]--></a><!----><!--]--></li><li><!--[--><a aria-current="page" href="/pages/developAttention/vehicleMiniprogram/#开发环境" class="router-link-active router-link-exact-active nav-link sidebar-item" aria-label="开发环境"><!--[--><!--]--> 开发环境 <!--[--><!--]--></a><!----><!--]--></li><li><!--[--><a aria-current="page" href="/pages/developAttention/vehicleMiniprogram/#启动步骤" class="router-link-active router-link-exact-active nav-link sidebar-item" aria-label="启动步骤"><!--[--><!--]--> 启动步骤 <!--[--><!--]--></a><!----><!--]--></li><li><!--[--><a aria-current="page" href="/pages/developAttention/vehicleMiniprogram/#注意事项" class="router-link-active router-link-exact-active nav-link sidebar-item" aria-label="注意事项"><!--[--><!--]--> 注意事项 <!--[--><!--]--></a><ul class="sidebar-sub-items"><li><!--[--><a aria-current="page" href="/pages/developAttention/vehicleMiniprogram/#_1-拉取代码" class="router-link-active router-link-exact-active nav-link sidebar-item" aria-label="1.拉取代码"><!--[--><!--]--> 1.拉取代码 <!--[--><!--]--></a><!----><!--]--></li><li><!--[--><a aria-current="page" href="/pages/developAttention/vehicleMiniprogram/#_2-新建页面" class="router-link-active router-link-exact-active nav-link sidebar-item" aria-label="2.新建页面"><!--[--><!--]--> 2.新建页面 <!--[--><!--]--></a><!----><!--]--></li><li><!--[--><a aria-current="page" href="/pages/developAttention/vehicleMiniprogram/#_3-底部安全距离" class="router-link-active router-link-exact-active nav-link sidebar-item" aria-label="3.底部安全距离"><!--[--><!--]--> 3.底部安全距离 <!--[--><!--]--></a><!----><!--]--></li><li><!--[--><a aria-current="page" href="/pages/developAttention/vehicleMiniprogram/#_4-静态资源" class="router-link-active router-link-exact-active nav-link sidebar-item" aria-label="4.静态资源"><!--[--><!--]--> 4.静态资源 <!--[--><!--]--></a><!----><!--]--></li><li><!--[--><a aria-current="page" href="/pages/developAttention/vehicleMiniprogram/#_5-网络请求" class="router-link-active router-link-exact-active nav-link sidebar-item" aria-label="5.网络请求"><!--[--><!--]--> 5.网络请求 <!--[--><!--]--></a><!----><!--]--></li><li><!--[--><a aria-current="page" href="/pages/developAttention/vehicleMiniprogram/#_6-自定义组件覆盖uview组件样式问题" class="router-link-active router-link-exact-active nav-link sidebar-item" aria-label="6.自定义组件覆盖uview组件样式问题"><!--[--><!--]--> 6.自定义组件覆盖uview组件样式问题 <!--[--><!--]--></a><!----><!--]--></li><li><!--[--><a aria-current="page" href="/pages/developAttention/vehicleMiniprogram/#_7-onlaunch异步问题" class="router-link-active router-link-exact-active nav-link sidebar-item" aria-label="7.onLaunch异步问题"><!--[--><!--]--> 7.onLaunch异步问题 <!--[--><!--]--></a><!----><!--]--></li></ul><!--]--></li><li><!--[--><a aria-current="page" href="/pages/developAttention/vehicleMiniprogram/#项目目录" class="router-link-active router-link-exact-active nav-link sidebar-item" aria-label="项目目录"><!--[--><!--]--> 项目目录 <!--[--><!--]--></a><!----><!--]--></li></ul><!--]--><!--]--></ul><!--[--><!--]--></aside><!--]--><!--[--><main class="page"><!--[--><!--]--><div class="theme-default-content"><!--[--><h1 id="小程序端开发事项" tabindex="-1"><a class="header-anchor" href="#小程序端开发事项" aria-hidden="true">#</a> 小程序端开发事项</h1><h2 id="技术栈" tabindex="-1"><a class="header-anchor" href="#技术栈" aria-hidden="true">#</a> 技术栈</h2><ul><li><a href="https://cn.vuejs.org/" target="_blank" rel="noopener noreferrer">Vue@2.x<span><svg class="icon outbound" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewbox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><!--[--><span class="sr-only">open in new window</span><!--]--></span></a></li><li><a href="https://vuex.vuejs.org/zh/" target="_blank" rel="noopener noreferrer">Vuex@3.x<span><svg class="icon outbound" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewbox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><!--[--><span class="sr-only">open in new window</span><!--]--></span></a></li><li><a href="https://uniapp.dcloud.io/" target="_blank" rel="noopener noreferrer">uni-app<span><svg class="icon outbound" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewbox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><!--[--><span class="sr-only">open in new window</span><!--]--></span></a></li><li><a href="https://v1.uviewui.com/" target="_blank" rel="noopener noreferrer">uview-ui@1.8.4<span><svg class="icon outbound" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewbox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><!--[--><span class="sr-only">open in new window</span><!--]--></span></a></li></ul><h2 id="开发环境" tabindex="-1"><a class="header-anchor" href="#开发环境" aria-hidden="true">#</a> 开发环境</h2><p><code>HBuilderx</code> + <code>微信开发者工具</code></p><h2 id="启动步骤" tabindex="-1"><a class="header-anchor" href="#启动步骤" aria-hidden="true">#</a> 启动步骤</h2><ol><li>拖动项目文件夹到HBuilderx侧边栏</li><li>运行到小程序模拟器 -&gt; 微信开发者</li></ol><p>注意事项：请在微信开发者工具找到 设置—&gt;安全设置 打开服务端口以便Hbuilderx拉起微信开发者工具</p><h2 id="注意事项" tabindex="-1"><a class="header-anchor" href="#注意事项" aria-hidden="true">#</a> 注意事项</h2><h3 id="_1-拉取代码" tabindex="-1"><a class="header-anchor" href="#_1-拉取代码" aria-hidden="true">#</a> 1.拉取代码</h3><p><strong>每次获取最新的代码后，请在HBuilderX中关闭所有的页签后再进行代码编写！！！</strong></p><p>该步骤主要原因为远程仓库更新了文件，Hbuilderx未关闭的页签会发生不同步该文件的情况。</p><h3 id="_2-新建页面" tabindex="-1"><a class="header-anchor" href="#_2-新建页面" aria-hidden="true">#</a> 2.新建页面</h3><p><strong>小程序页面相关配置在pages.json中</strong></p><ol><li>确定该模块属于主包还是分包</li><li>主包页面放置pages属性中，分包页面放置subPackages属性中</li></ol><h3 id="_3-底部安全距离" tabindex="-1"><a class="header-anchor" href="#_3-底部安全距离" aria-hidden="true">#</a> 3.底部安全距离</h3><p>适用场景：设计稿底部存在按钮等</p><p>添加方法：</p><ul><li><p>底部没有额外间距：使用uview提供的<code>safe-area-inset</code> 类名即可</p></li><li><p>底部有额外间距</p><div class="language-scss ext-scss line-numbers-mode"><pre class="language-scss"><code><span class="token comment">// 底部有10rpx内间距</span>
<span class="token property">padding-bottom</span><span class="token punctuation">:</span> 10rpx<span class="token punctuation">;</span>
<span class="token property">padding-bottom</span><span class="token punctuation">:</span> <span class="token function">calc</span><span class="token punctuation">(</span>10rpx <span class="token operator">+</span> <span class="token function">constant</span><span class="token punctuation">(</span>safe-area-inset-bottom<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token property">padding-bottom</span><span class="token punctuation">:</span> <span class="token function">calc</span><span class="token punctuation">(</span>10rpx <span class="token operator">+</span> <span class="token function">env</span><span class="token punctuation">(</span>safe-area-inset-bottom<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><div class="line-numbers"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div></li></ul><h3 id="_4-静态资源" tabindex="-1"><a class="header-anchor" href="#_4-静态资源" aria-hidden="true">#</a> 4.静态资源</h3><p><strong>项目中使用到的所有图片、视频请上传到七牛云<code>cosla-static</code> 空间下，并添加<code>miniprogram/</code>路径前缀</strong>，新版七牛云直接上传至<code>miniprogram</code>目录即可。</p><p>七牛云示例外链：http://static.shinwell.cn/miniprogram/camera_icon.png</p><p><em>七牛云账号请咨询其他前端小伙伴</em></p><h3 id="_5-网络请求" tabindex="-1"><a class="header-anchor" href="#_5-网络请求" aria-hidden="true">#</a> 5.网络请求</h3><p>所有的网络请求方法均放置在<code>api</code>文件夹中，根据模块命名请求文件，模块中放置该模块所有的请求方法。</p><p>请求方法书写示例：</p><div class="language-javascript ext-js line-numbers-mode"><pre class="language-javascript"><code><span class="token comment">// user.js</span>

<span class="token comment">// 根据authCode获取临时token</span>
<span class="token keyword">const</span> <span class="token function-variable function">getOpenApiTempToken</span> <span class="token operator">=</span> <span class="token parameter">authCode</span> <span class="token operator">=&gt;</span> uni<span class="token punctuation">.</span>$u<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">/open-api/temp-token/</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>authCode<span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">)</span>

<span class="token comment">// 根据临时token获取当前用户的token</span>
<span class="token keyword">const</span> <span class="token function-variable function">getUserToken</span> <span class="token operator">=</span> <span class="token parameter">tempToken</span> <span class="token operator">=&gt;</span> uni<span class="token punctuation">.</span>$u<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">/user/token/</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>tempToken<span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">)</span>

<span class="token comment">// 获取用户信息</span>
<span class="token keyword">const</span> <span class="token function-variable function">getUserInfo</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> uni<span class="token punctuation">.</span>$u<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">&#39;/user/info&#39;</span><span class="token punctuation">)</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
	getOpenApiTempToken<span class="token punctuation">,</span>
	getUserToken<span class="token punctuation">,</span>
	getUserInfo
<span class="token punctuation">}</span>

</code></pre><div class="line-numbers"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><p>注意事项：<strong>项目使用统一管理api请求的方法，故请求方法必须导出才能在页面中使用，且所有请求方法均不能出现重名。</strong></p><p>调用请求方法示例：</p><div class="language-javascript ext-js line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">const</span> <span class="token punctuation">{</span> data<span class="token operator">:</span> info <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token keyword">this</span><span class="token punctuation">.</span>$u<span class="token punctuation">.</span>api<span class="token punctuation">.</span><span class="token function">getUserInfo</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre><div class="line-numbers"><span class="line-number">1</span><br></div></div><blockquote><p>对于网络请求，若响应返回有businessCode且其中code属性值不为1时，默认情况下会弹出错误弹窗。若不需要该弹窗，请在对应请求下添加请求头hideError: &#39;true&#39;。不使用布尔类型的原因为，布尔类型的在响应拦截获取到的值为[object Boolean]</p></blockquote><div class="language-javascript ext-js line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">const</span> <span class="token function-variable function">inspectionReportQuery</span> <span class="token operator">=</span> <span class="token parameter">data</span> <span class="token operator">=&gt;</span> uni<span class="token punctuation">.</span>$u<span class="token punctuation">.</span><span class="token function">post</span><span class="token punctuation">(</span><span class="token string">&#39;/inspection-report/query&#39;</span><span class="token punctuation">,</span> data <span class="token punctuation">,</span> <span class="token punctuation">{</span> hideError<span class="token operator">:</span> <span class="token string">&#39;true&#39;</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre><div class="line-numbers"><span class="line-number">1</span><br></div></div><h3 id="_6-自定义组件覆盖uview组件样式问题" tabindex="-1"><a class="header-anchor" href="#_6-自定义组件覆盖uview组件样式问题" aria-hidden="true">#</a> 6.自定义组件覆盖uview组件样式问题</h3><p>默认情况下，自定义组件中无法覆盖uview组件样式，原因是小程序中存在样式隔离。解决方案为启用样式共享：</p><div class="language-javascript ext-js line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    name<span class="token operator">:</span> <span class="token string">&#39;CustomComponent&#39;</span><span class="token punctuation">,</span>
    options<span class="token operator">:</span><span class="token punctuation">{</span>
        styleIsolation<span class="token operator">:</span> <span class="token string">&quot;shared&quot;</span><span class="token punctuation">,</span> <span class="token comment">// 启用样式共享</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h3 id="_7-onlaunch异步问题" tabindex="-1"><a class="header-anchor" href="#_7-onlaunch异步问题" aria-hidden="true">#</a> 7.onLaunch异步问题</h3><p>产生情况：onLaunch中使用异步请求，同时小程序启动页在onLoad等钩子函数调用网络请求时需要onLaunch的数据。此时，onLaunch中异步请求可能还未执行完成导致启动页拿不到数据引起报错。</p><p>解决方法：</p><ol><li><p>main.js</p><div class="language-javascript ext-js line-numbers-mode"><pre class="language-javascript"><code><span class="token class-name">Vue</span><span class="token punctuation">.</span>prototype<span class="token punctuation">.</span>$onLaunched <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Promise</span><span class="token punctuation">(</span><span class="token parameter">resolve</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
	<span class="token class-name">Vue</span><span class="token punctuation">.</span>prototype<span class="token punctuation">.</span>$isResolve <span class="token operator">=</span> resolve
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre><div class="line-numbers"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div></li><li><p>App.vue</p><div class="language-javascript ext-js line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">async</span> <span class="token function">onLaunch</span><span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">try</span><span class="token punctuation">{</span>
   	<span class="token keyword">await</span> 异步请求
    <span class="token comment">//onLaunch异步执行完成</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">$isResolve</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token keyword">catch</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span><span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div></li><li><p>启动页</p><div class="language-javascript ext-js line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">async</span> <span class="token function">onLoad</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment">//等待onLaunch异步完成</span>
  <span class="token keyword">await</span> <span class="token keyword">this</span><span class="token punctuation">.</span>$onLaunched
 	<span class="token operator">...</span><span class="token punctuation">.</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
</code></pre><div class="line-numbers"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div></li></ol><h2 id="项目目录" tabindex="-1"><a class="header-anchor" href="#项目目录" aria-hidden="true">#</a> 项目目录</h2><details class="custom-container details"><summary>点击展开</summary><div class="language-text ext-text line-numbers-mode"><pre class="language-text"><code>.
├── App.vue                                 // 根组件
├── README.md
├── api                                     // 网络请求
├── common                                
│   ├── common.style.scss                   // 全局样式
│   ├── http.api.js                         // 挂载全局请求的方法
│   ├── http.interceptor.js                 // 请求拦截器
│   └── settings.js                         // 项目配置
├── components                              // 全局组件
├── main.js
├── manifest.json                           // 项目配置
├── package-lock.json
├── package.json
├── pages                                   // 页面
│   ├── inspection                          // 检查分包
│   └── login
│       └── index.vue
├── pages.json                              // 页面配置
├── static
│   └── logo.jpg
├── store                                   // vuex
│   ├── $u.mixin.js
│   └── index.js
├── uni.scss
├── uni_modules
├── utils                                   // 工具类
│   ├── common.js
│   └── qnBase64.js
└── uview-ui                            

</code></pre><div class="line-numbers"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br></div></div></details><!--]--></div><footer class="page-meta"><!----><div class="meta-item last-updated"><span class="meta-item-label">上次更新: </span><span class="meta-item-info">2022-4-14 19:12:57</span></div><div class="meta-item contributors"><span class="meta-item-label">Contributors: </span><span class="meta-item-info"><!--[--><!--[--><span class="contributor" title="email: 1928537900@qq.com">jinleiFu</span><!----><!--]--><!--]--></span></div></footer><!----><!--[--><!--]--></main><!--]--></div><!----><!--]--></div>
    <script src="/assets/js/runtime~app.7eeb5ba6.js" defer></script><script src="/assets/js/6135.d16fec79.js" defer></script><script src="/assets/js/app.4602c005.js" defer></script>
  </body>
</html>
